package com.fifth.apartment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fifth.apartment.entity.BuildingInfo;
import com.fifth.apartment.mapper.BuildingInfoMapper;
import com.fifth.apartment.service.BuildingInfoService;
import com.fifth.apartment.vo.PageQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 公寓信息表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-07-11
 */
@Service
public class BuildingInfoServiceImpl extends ServiceImpl<BuildingInfoMapper, BuildingInfo> implements BuildingInfoService {
@Autowired
private BuildingInfoMapper buildingInfoMapper;
    @Override
    public Page<BuildingInfo> findPage(PageQueryVO vo) {
        Integer currentPage = vo.getCurrentPage();
        Integer pageSize = vo.getPageSize();
        String queryString = vo.getQueryString();
        //封装Page对象
        Page<BuildingInfo> page = new Page<>(currentPage , pageSize);
        //封装查询条件
        LambdaQueryWrapper<BuildingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.hasLength(queryString) , BuildingInfo::getPhone , queryString)
                .or().like(StringUtils.hasLength(queryString) , BuildingInfo::getName , queryString);
        //分页查询数据
        Page<BuildingInfo> Page = this.baseMapper.selectPage(page, lambdaQueryWrapper);
        return Page;
    }

    @Override
    public BuildingInfo[] getBuildings() {
        BuildingInfo[] buildings = buildingInfoMapper.getBuildings();
        return buildings;
    }
}
